home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / CPP / WCLASS95.ZIP / CPPMAIN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-02  |  8.7 KB  |  184 lines

  1. //This sample main program may be used to test ANSI C++ code generation scripts.
  2. //In With Class load cppcar.omt.  Run the scripts cpphead0.sct and cppfunc0.sct,
  3. //cpphead1.sct and cppfunc1.sct, cpphead2.sct and cppfunc2.sct or borland scripts.
  4. //Create a project in your C++ environment.  Add cppmain.cpp, vehicle.cpp, 
  5. //car.cpp, motor.cpp, passengr.cpp, tire.cpp, and clllrphn.cpp.
  6. //Comments and suggestions are solicited Richard Felsinger, RCF Associates
  7. //960 Scottland Dr, Mt Pleasant, SC 29464 tele 803-881-3648 71162.755@compuserve.com
  8.  
  9. #include "car.h"
  10. #include <iostream.h>
  11. #include <cstring.h>
  12.  
  13. int main ()
  14. {
  15. /*                               
  16.   //With cppcar.omt generate code with cpphead0.sct and cppfunc0.sct
  17.   //This is the simplest code generation using all compiler defaults.
  18.   Car car1;                 //invokes default constructor
  19.   Car car2 (car1);          //invokes default copy constructor
  20.   car1 = car2;              //invokes default assignment operator
  21.   car1.registerIt();
  22.   car1.operate();
  23.   car1.makePhoneCall();
  24.   car1.inflateTire();
  25.   car1.checkPassengerSeatBelt();
  26.   return 0;
  27.  
  28.  
  29.  
  30. */
  31. /*
  32.   //With cppcar.omt generate code with cpphead1.sct and cppfunc1.sct
  33.   //These scripts use iostream.h
  34.   Car car1;                 //invokes default constructor
  35.   Car car2 (car1);          //invokes default copy constructor
  36.   car1 = car2;              //invokes default assignment operator
  37.   cout << car1;             //invokes operator<< for text output
  38.  
  39.   Car car3 (55, 0);          //Invokes constructor with arguments
  40.   cout << car3;
  41.   
  42.   Car car4;
  43.   cin >> car4;
  44.   cout << car4;
  45.  
  46.   if (car1 == car4) cout << "Cars are equal." << "\n";
  47.   else cout << "Cars are not equal." << "\n";
  48.  
  49.   car1.registerIt();
  50.   car1.operate();
  51.   car1.makePhoneCall();
  52.   car1.inflateTire();
  53.   car1.checkPassengerSeatBelt();
  54.   return 0;
  55. */
  56. /*
  57.   //With cppcar.omt generate code with cpphead2.sct and cppfunc2.sct
  58.   //This is the simplest code generation using all compiler defaults.
  59.  
  60.   Car car1;                                                     //Invokes default constructor
  61.   cin >> car1;                          //Invokes input function >>
  62.   cout << car1;                                 //Invokes output function << 
  63.  
  64.   int aSpeed, aNumber;                  //Create int variables
  65.   long aTotal;                          //Create long variable
  66.   car1.setspeed (55);                                   //Invokes set accessor function
  67.   aSpeed = car1.getspeed();                     //Invokes get accessor function 
  68.   aSpeed = 65;
  69.   Car::settotalCarsBuilt (9999);     //Invokes set accessor function for static data member
  70.   aTotal = Car::gettotalCarsBuilt(); //Invokes get accessor function for static data member
  71.  
  72.   Car car2 (car1);                                //Invokes copy constructor
  73.   Car car3 (55, 0);                                  //Invokes constructor with arguments
  74.   car1 = car2;                                    //Invokes assignment operator
  75.                                                     //Invokes equality operator
  76.   if (car1 == car3) cout << "Cars are equal." << "\n";
  77.   else cout << "Cars are not equal." << "\n";
  78.  
  79.   try {
  80.      car1.registerIt(); }                    //Invokes redefined virtual function
  81.   catch (string registerItError) { cout << "RegisterIt Error"; }
  82.   catch (...) { cout << "Unknown Error" << endl; }
  83.  
  84.   try {
  85.      car1.operate();  }                     //Invokes a function    
  86.   catch (string operateError) { cout << "Operate Error"; }
  87.   catch (...) { cout << "Unknown Error" << endl; }
  88.   
  89.   car1.setnumber(1111);                 //Invokes set accessor function from base class
  90.   aNumber = car1.getnumber();  //Invokes get accessor function from base class
  91.  
  92.   Motor motor1;     //Create motor objects
  93.   try {
  94.      car1.operate(); }          //Invokes traversal function to access aggregation part
  95.   catch (string operateError) { cout << "Operate Error"; }
  96.   catch (...) { cout << "Unknown Error" << endl; }
  97.   
  98.   car1.setMotor(motor1);    //Invokes set accessor function to set aggregation part
  99.   const Motor motor2 = car1.getMotor(); //Invokes get accessor function to get aggregation part
  100.  
  101.   CellularPhone phone1;       //Create phone objects
  102.   car1.setCellularPhone (&phone1);    //Invokes set accessor function for association object
  103.  
  104.   try {
  105.      car1.makePhoneCall(); }        //Invokes traversal function to access association object
  106.   catch (string makePhoneCallError) { cout << "Make Phone Call Error"; }
  107.   catch (...) { cout << "Unknown Error" << endl; }
  108.   
  109.   const CellularPhone phone2 = *car1.getCellularPhone ();  //Invokes get accessor function to get association object
  110.   int phoneStatus = car1.existsCellularPhone ();  //Invokes exists function for association object
  111.   phoneStatus = car1.existsCellularPhone (&phone1);//Invokes exists function for association object
  112.  
  113.   try {
  114.      car1.removeCellularPhone();}         //Invokes remove function for association object
  115.   catch (string noCellularPhone) { cout << "No Cellular Phone"; }
  116.   catch (...) { cout << "Unknown Error" << endl; }
  117.   
  118.   Tire tireArray[4];                  //Creates array of tire objects
  119.   Tire* pTireArray = tireArray;       //Creates pointer to the array of tire objects
  120.   pTireArray = (Tire*)car1.getTireCollection(); //Invokes get accessor function for collection of aggregation objects
  121.   car1.setTireCollection (pTireArray);   //Invokes set accessor function for collection of aggregation objects
  122.  
  123.   const Tire tire1;                       //Creates tire objects
  124.   tire1 = car1.getFirstTire();           //Invokes get accessor function for 1:M aggregation object
  125.   int tireStatus = car1.existsTire (tire1);//Invokes exists function for 1:M aggregation object
  126.  
  127.   try {
  128.      car1.inflateTire(); }                                                  //Invokes traversal function for 1:M aggregation object
  129.   catch (string inflateTireError) { cout << "Inflate Tire Error"; }
  130.   catch (...) { cout << "Unknown Error" << endl; }
  131.   
  132.   Passenger passengerArray[4];                                          //Creates array of passengers
  133.   Passenger* pPassengerArray = passengerArray;          //Creates pointer to array of passenger objects
  134.   pPassengerArray = (Passenger*)car1.getPassengerCollection(); //Invokes get accessor function for collection of association objects
  135.   car1.setPassengerCollection (pPassengerArray);   //Invokes set accessor function for collection of association objects
  136.   
  137.   Passenger passenger1, passenger2, passenger3, passenger4; //Create passenger objects
  138.  
  139.   try {
  140.      car1.addPassenger(&passenger1);  }       //Invokes add function for 1:M association object
  141.   catch (string PassengerCollectionFull) { cout << "Passenger Collection Full" << endl;}
  142.   catch (...) { cout << "Unknown Error" << endl; }
  143.   
  144.   try {
  145.      car1.addPassenger(&passenger2); }              //Invokes add function for 1:M association object
  146.   catch (string PassengerCollectionFull) { cout << "Passenger Collection Full" << endl;}
  147.   catch (...) { cout << "Unknown Error" << endl; }
  148.   
  149.   try {
  150.      car1.addPassenger(&passenger3); }        //Invokes add function for 1:M association object
  151.   catch (string PassengerCollectionFull) { cout << "Passenger Collection Full" << endl;}
  152.   catch (...) { cout << "Unknown Error" << endl; }
  153.   
  154.   try {
  155.      car1.addPassenger(&passenger4); }        //Invokes add function for 1:M association object
  156.   catch (string PassengerCollectionFull) { cout << "Passenger Collection Full" << endl;}
  157.   catch (...) { cout << "Unknown Error" << endl; }
  158.   
  159.   try {
  160.      car1.checkPassengerSeatBelt(); }                               //Invokes traversal function for 1:M association object
  161.   catch (string PassengerCollectionFull) { cout << "Passenger Collection Full" << endl;}         
  162.   catch (...) { cout << "Unknown Error" << endl; }
  163.   
  164.   int passengerStatus;
  165.   passengerStatus = car1.existsPassenger ();        //Invokes exists function for association object
  166.   passengerStatus = car1.existsPassenger (&passenger1);   //Invokes exists function for association object
  167.  
  168.   cin >> car1;                                      //Invokes the >> operator to input text information
  169.   cout << car1;                                     //Invokes the << operator to output text information
  170.  
  171.   try  {
  172.     car1.removeLastPassenger ();  }                //Invokes removeLast function for 1:M association object
  173.   catch (string noPassengerError) { cout << "No Passenger Error" << endl; }
  174.   catch (...) { cout << "Unknown Error" << endl; }
  175.   
  176.   try {
  177.      car1.removeAllPassengers(); }            //Invokes removeAll function for 1:M association object
  178.   catch (string noPassengerError) { cout << "No Passenger Error" << endl; }
  179.   catch (...) { cout << "Unknown Error" << endl; }
  180.  
  181.   return 0;                     //Default destructor is invoked
  182. */
  183. }
  184.